﻿using System;
using System.Collections;
using System.Collections.Generic;
using com.youzu.warh.protocol;
using FlowCanvas;
using FlowCanvas.Nodes;
using LogSystem;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.AI;

namespace Yoozoo.Gameplay.Liberty.StreetEvent
{
    public class ChangeStreetEventNpcWeapon : CallableActionNode<int,int, bool>
    {
        public override void Invoke(int streetNpcId, int weaponId, bool enterBattleState)
        {
            if (streetNpcId != LibertyAIUtils.PLAYER_AI_ID)
            {
                var m = StreetEventManager.GetInstance("").GetMonster(streetNpcId);
                if (m != null)
                {
                    var aiEntity = LibertyAIUtils.AIManager.NpcBirthManager.GetNpc(m.uniqueId);
                    if (aiEntity != null)
                    {
                        aiEntity.WeaponSystem.AddWeapon(weaponId);
                        aiEntity.WeaponSystem.EquipWeapon(weaponId);
                        // aiEntity.data.selectedWeaponId = weaponId;
                        aiEntity.battleAgent.ChangeWeapon(weaponId);
                        // aiEntity.WeaponSystem.ChangeWeapon(weaponId);
                        // if (enterBattleState)
                        // {
                        //     BattleState battleState = BattleState.None;
                        //     PbWeaponDataConfig weaponDataConfig = LibertyConfigManager.GetInstance().GetWeaponDataConfig(weaponId);
                        //     if (weaponDataConfig != null)
                        //     {
                        //         battleState = (BattleState)weaponDataConfig.battle_state;
                        //     }
                        //     aiEntity.viewer.animationAgent.EnterBattleState(battleState);
                        // }
                    }
                }
            }
            else
            {
                LibertyAIUtils.PlayerController.playerEntity.AIEntity.battleAgent.ChangeWeapon(weaponId);
            }
        }
        
    }
}